package com.weetop.cfw.mine.adapter

import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import com.blankj.utilcode.util.ConvertUtils.dp2px
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.coorchice.library.SuperTextView
import com.weetop.cfw.R
import com.weetop.cfw.bean.WorkshopWarehouseListBean
import com.weetop.cfw.constants.UrlConstants
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter
import com.zhy.view.flowlayout.TagFlowLayout

class WorkshopBrowseRecordAdapter(
    layoutId: Int,
    dataList: List<WorkshopWarehouseListBean.DataBean>
) : BaseQuickAdapter<WorkshopWarehouseListBean.DataBean, BaseViewHolder>(layoutId, dataList) {


    override fun convert(helper: BaseViewHolder, item: WorkshopWarehouseListBean.DataBean?) {
        val textWorkshopImg = helper.getView<ImageView>(R.id.textWorkshopImg)
        val flowWorkshopDesc: TagFlowLayout = helper.getView(R.id.flowWorkshopDesc)
        val tagList = ArrayList<String?>()
        if (item?.isalone?.trim() != "") {
            tagList.add(item?.isalone)
        } else {

        }
        if (item?.haslift?.trim() != "") {
            tagList.add(item?.haslift)
        } else {

        }
        if (item?.floor?.trim() != "") {
            tagList.add("${item?.floor}层")
        } else {

        }

        flowWorkshopDesc.adapter = object : TagAdapter<String>(tagList) {
            override fun getView(parent: FlowLayout?, position: Int, t: String?): View {
                val textItemWorkshopDescFlowLayoutView = LayoutInflater.from(mContext)
                    .inflate(R.layout.layout_item_workshop_desc_flow, parent, false)
                val textItemWorkshopDesc =
                    textItemWorkshopDescFlowLayoutView.findViewById<SuperTextView>(R.id.textItemWorkshopDesc)
                textItemWorkshopDesc.text = tagList[position]
                return textItemWorkshopDescFlowLayoutView
            }
        }
        Glide.with(mContext).load("${UrlConstants.baseUrl}${item?.imgurl}").apply(
            RequestOptions().transforms(
                CenterCrop(),
                RoundedCorners(dp2px(5f))
            )
        ).error(R.drawable.cover).into(textWorkshopImg)
//        textWorkshopImg.setUrlImage("${UrlConstants.baseUrl}${item?.imgurl}")
        helper.setText(R.id.textWorkshopName, item?.title)
            .setText(R.id.textWorkshopAddress, "地址：${item?.address}")
            .setText(R.id.textWorkshopArea, "面积：${item?.area}㎡")

    }
}